﻿<Window x:Class="HyperbolicTest.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ht="clr-namespace:Hyperbolic;assembly=Hyperbolic"
    xmlns:my="clr-namespace:HyperbolicTest"
    Title="HyperbolicTest" Height="600" Width="800"
    >

    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="AquaGelButtonResource.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>

    <Grid Name="grid3" Grid.Column="2" Margin="20" >
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="224*" />
            <ColumnDefinition Width="324*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="213*" />
        </Grid.RowDefinitions>

        <Grid.Resources>

            <DataTemplate x:Key="MyDataTemplate">
                <Button          
                    DataContext="{Binding Path=Node}"
                    Content="{Binding Path=MyName}"
                    Style="{StaticResource RedAquaGelButtonTemplateStyle}"
                    Background="sc#1, 0.979549646, 0.6541397, 0.0275757164"
                    />
            </DataTemplate>


            <Style TargetType="{x:Type ht:TreeView}">
                <Setter Property="ItemTemplate" Value="{StaticResource MyDataTemplate}"/>
            </Style>

        </Grid.Resources>

        <ht:TreeView x:Name="htree" Grid.Column="2" Grid.Row="1" Margin="5,5,5,5"/>

        <ListBox ItemsSource="{Binding Path=NodeModelCollection}"
                 Name="treeView3" Grid.Row="3" Margin="5,5,5,5" ScrollViewer.VerticalScrollBarVisibility="Visible"
				ScrollViewer.HorizontalScrollBarVisibility="Visible"
				MouseDoubleClick="TreeItemDoubleClick" Grid.Column="1">
            <ListBox.Resources>
                <my:ConvertLevelToIndent x:Key="ConvertLevelToIndent" />

                <Style x:Key="ExpandCollapseToggleStyle" TargetType="{x:Type ToggleButton}">
                    <Setter Property="Focusable" Value="False"/>
                    <Setter Property="Width" Value="16"/>
                    <Setter Property="Height" Value="16"/>
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type ToggleButton}">
                                <Border Width="16" Height="16" Background="Transparent" Padding="5,5,5,5">
                                    <Path x:Name="ExpandPath" Fill="Transparent" Stroke="#FF989898" Data="M0,0 L0,6 L6,0 z">
                                        <Path.RenderTransform>
                                            <RotateTransform Angle="135" CenterX="3" CenterY="3"/>
                                        </Path.RenderTransform>
                                    </Path>
                                </Border>
                                <ControlTemplate.Triggers>
                                    <Trigger Property="IsMouseOver" Value="True">
                                        <Setter TargetName="ExpandPath" Property="Stroke" Value="#FF1BBBFA"/>
                                        <Setter TargetName="ExpandPath" Property="Fill" Value="Transparent"/>
                                    </Trigger>

                                    <Trigger Property="IsChecked" Value="True">
                                        <Setter TargetName="ExpandPath" Property="RenderTransform">
                                            <Setter.Value>
                                                <RotateTransform Angle="180" CenterX="3" CenterY="3"/>
                                            </Setter.Value>
                                        </Setter>
                                        <Setter TargetName="ExpandPath" Property="Fill" Value="#FF595959"/>
                                        <Setter TargetName="ExpandPath" Property="Stroke" Value="#FF262626"/>
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </ListBox.Resources>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <Border Width="{Binding Path=Node.Level, Converter={StaticResource ConvertLevelToIndent}}" />
                        <ToggleButton x:Name="tb" ClickMode="Press" IsChecked="{Binding Path=IsExpanded}" Style="{StaticResource ExpandCollapseToggleStyle}"/>
                        <TextBlock Text="{Binding Path=Node.Name}" />
                    </StackPanel>
                    <DataTemplate.Triggers>
                        <DataTrigger Binding="{Binding Path=Key.SubKeyCount}" Value="0">
                            <Setter Property="Visibility" TargetName="tb" Value="Hidden"/>
                        </DataTrigger>
                    </DataTemplate.Triggers>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
</Window>
